package com.cloud.tsp.controller;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.cloud.api.constants.StrVo;
import com.cloud.api.domain.model.*;
import com.cloud.core.exception.MyException;
import com.cloud.core.util.R;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.tsp.service.IEvModelInformationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2023-12-20
 */
@RestController
@RequestMapping("/ev-model-information")
public class EvModelInformationController {


    @Resource
    private IEvModelInformationService evModelInformationService;

    @Tag(name = "v1.0")
    @Operation(summary = "根据车型查询公告型号（管理）")
    @PostMapping("/getNoticeModelById")
    @Log(title = "车型管理-根据车型查询公告型号", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<String> selectNoticeModelById(@RequestBody @Valid StrVo para){
        String s = evModelInformationService.selectNoticeModelById(para.getId());
        return R.ok(s);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "根据车型查询全部车型信息（管理）")
    @PostMapping("/getByModelId")
    @Log(title = "车型管理-根据车型查询全部车型信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<EvModelInformation> selectByModelId(@RequestBody @Valid StrVo para){
        return R.ok(evModelInformationService.selectByModelId(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改车型基础信息（管理）")
    @PostMapping("/InsertOrUpdateBase")
    @Log(title = "车型管理-新增或修改车型基础信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdateBase(@RequestBody @Valid ModelBase para){
        evModelInformationService.InsertOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改车辆型号（管理）")
    @PostMapping("/InsertOrUpdateType")
    @Log(title = "车型管理-新增或修改车辆型号", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdateType(@RequestBody @Valid ModelType para){
        evModelInformationService.InsertOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改整车性能参数信息（管理）")
    @PostMapping("/InsertOrUpdatePerformance")
    @Log(title = "车型管理-新增或修改整车性能参数信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdatePerformance(@RequestBody @Valid ModelPerformance para){
        evModelInformationService.InsertOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改配件信息（管理）")
    @PostMapping("/InsertOrUpdateParts")
    @Log(title = "车型管理-新增或修改配件信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdateParts(@RequestBody @Valid ModelParts para){
        evModelInformationService.InsertOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改三电控制器信息（管理）")
    @PostMapping("/InsertOrUpdateController")
    @Log(title = "车型管理-新增或修改三电控制器信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdateController(@RequestBody @Valid ModelController para){
        evModelInformationService.InsertOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改储能装置信息（管理）")
    @PostMapping("/InsertOrUpdateEnergy")
    @Log(title = "车型管理-新增或修改储能装置信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdateEnergy(@RequestBody @Valid ModelEnergy para){
        evModelInformationService.InsertOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新能源车型基本信息导出")
    @PostMapping("/exportEvInformation")
    @Log(title = "车型管理-新能源车型基本信息导出", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    public void exportEvInformation(String id, HttpServletResponse response) throws IOException {
        if (StringUtil.isBlank(id)){
            throw new MyException("wds.exception.idNull");
        }
        evModelInformationService.exportEvInformation(id,response);
    }

}